<?php

namespace App\Console\Commands;
use App\Models\Category;
use App\Models\Circle;
use App\Models\CircleCategoryRelate;
use App\Models\City;
use Illuminate\Console\Command;

class CategoryCircleCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'category-circle';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        Category::where('parent_id', '!=', 0)->chunk(50, function ($list) {
            foreach ($list as $item) {
                $circle = Circle::create([
                    'user_id' => 1,
                    'is_area' => 0,
                    'title' => $item->title . '宠物圈',
                    'desc' => '欢迎关注并分享'.$item->title.'宠友圈，这里都是'.$item->title.'爱好者，欢迎大家组织线下活动',
                    'status' => Circle::STATUS_SUCCESS,
                    'logo' => $item->file_path
                ]);
                CircleCategoryRelate::create([
                    'circle_id' => $circle->id,
                    'circle_category_id' => 2
                ]);
            }
        });
    }
}
